<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .fade-enter,.fade-leave-to{
            opacity:0;
        }
        .fade-enter-active,.fade-leave-active{
            transition: opacity .9s;
        }
    </style>
</head>
<body>
    <div id="app">
        <button @click="toggleCom">切换</button>
        <transition name="fade">
            <keep-alive>
                <div :is="currentView"></div>
            </keep-alive>
        </transition>
    </div>
    <script src="/JS文件/vue.js"></script>
    <script>
        Vue.component("Aa",{
            template:'<h3>AAAAAAAA</h3>'
        })
        Vue.component("Bb",{
            template:'<h3>BBBBBBBBBB</h3>'
        })
        new Vue({
            el:'#app',
            data:{
                currentView:'Aa',
            },
            methods:{
                toggleCom(){
                    if(this.currentView=='Aa'){
                        this.currentView='Bb'
                    }else{
                        this.currentView='Aa'
                    }
                }
            }
        })
    </script>
</body>
</html>